package xyz.cerberu.cet.global.utils;


import xyz.cerberu.cet.global.domain.Result;

/**
 * @author β世界
 * Created on 16:32
 * @Description 响应结果创建工具
 */
public class ResultUtils {
    private static final String DEFAULT_SUCCESS_MESSAGE = "SUCCESS";
    private static final String DEFAULT_FAIL_MESSAGE = "FAIL";
    private static final int RESULT_CODE_SUCCESS = 200;
    private static final int RESULT_CODE_SERVER_ERROR = 500;

    /**
     * @author β世界 on 16:35 2020/4/10
     * @Description 获取一个相应成功的对象
     **/
    public static Result<Object> getSuccessResult(){
        Result<Object> result = new Result<>();
        result.setResultCode(RESULT_CODE_SUCCESS);
        result.setMessage(DEFAULT_SUCCESS_MESSAGE);
        return result;
    }

    /**
     * @author β世界 on 16:37 2020/4/10
     * @Description 设置一个相应成功的对象，并且设置其返回信息
     * @param message:信息
     * @return com.Cet.common.domain.Result
     **/
    public static Result<Object> genSuccessResult(String message) {
        Result<Object> result = new Result<>();
        result.setResultCode(RESULT_CODE_SUCCESS);
        result.setMessage(message);
        return result;
    }

    /**
     * @author β世界 on 16:36 2020/4/10
     * @Description 设置一个相应成功的对象，并且设置其数据
     * @param data:数据
     * @return com.Cet.common.domain.Result
     **/
    public static <T> Result<T> genSuccessResult(T data) {
        Result<T> result = new Result<>();
        result.setResultCode(RESULT_CODE_SUCCESS);
        result.setMessage(DEFAULT_SUCCESS_MESSAGE);
        result.setData(data);
        return result;
    }

    /**
     * @author β世界 on 23:26 2020/4/10
     * @Description 创建一个失败的对象，并设置其信息
     * @param message:
     * @return com.Cet.common.domain.Result
     **/
    public static Result<Object> genFailResult(String message) {
        Result<Object> result = new Result<>();
        result.setResultCode(RESULT_CODE_SERVER_ERROR);
        if (message.isEmpty() && "".equals(message.trim())) {
            result.setMessage(DEFAULT_FAIL_MESSAGE);
        } else {
            result.setMessage(message);
        }
        return result;
    }
    
    
    /**
     * @author β世界 on 23:27 2020/4/10
     * @Description 创建一个错误的结果对象，自定义信息和响应码
     * @param code:响应码
     * @param message:信息
     * @return com.Cet.common.domain.Result
     **/
    public static Result<Object> genErrorResult(int code, String message) {
        Result<Object> result = new Result<>();
        result.setResultCode(code);
        result.setMessage(message);
        return result;
    }

    /**
     * @author β世界 on 23:27 2020/4/10
     * @Description 创建一个错误的结果对象，自定义信息和响应码，和相应的返回信息
     * @param code:响应码
     * @param message:信息
     * @return com.Cet.common.domain.Result
     **/
    public static <T> Result<T> genErrorResult(int code, String message,T object) {
        Result<T> result = new Result<>();
        result.setResultCode(code);
        result.setMessage(message);
        result.setData(object);
        return result;
    }

}
